package com.felight.ems.collections;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;

import org.apache.commons.lang3.RandomStringUtils;


//import java.util.Random;



public class ListBenchMarking {
	
	//if API is not used then this method can be used.
	/*public String randomString(int length){
		Random random = new Random();
		String str = ""+random.nextInt()+""+(char)random.nextInt();
		return str;
	}*/
	
	public ArrayList<String> generateRandomArrayList(int size){
		ArrayList<String> list = new ArrayList<String>();
		long start = System.currentTimeMillis();
		for(int i =0;i<size;i++){
			//list.add(RandomStringUtils.random(20));//making use of API
			list.add(RandomStringUtils.randomAlphabetic(20));//generates random string of only alphabet
			//list.add(RandomStringUtils.randomAlphanumeric(20));//generates alphanumeric string
			//list.add(RandomStringUtils.randomAscii(20));
			//list.add(RandomStringUtils.randomNumeric(20));
		}
		System.out.println("time taken to generate arraylist of random string:"+(System.currentTimeMillis()-start));
		return list;
	}
	
	
	//this method is creating the clone of arraylist.
	public LinkedList<String> cloneArrayList(ArrayList<String> list){
		Iterator<String> iterator = list.iterator();
		LinkedList<String> linkedlist = new LinkedList<String>();
		long start = System.currentTimeMillis();
		while(iterator.hasNext()){
			linkedlist.add(iterator.next());
		}
		System.out.println("time taken to generate linkedlist of random string:"+(System.currentTimeMillis()-start));
		return linkedlist;
	}
	
	// this method will generate different random string for linkedlist.
	/*public LinkedList<String> generateRandomLinkedList(int size){
		LinkedList<String> list = new LinkedList<String>();
		for(int i =0;i<size;i++){
			list.add(randomString(20));
		}
		return list;
	}*/
	
	public long benchMarkArrayList(ArrayList<String> list,int pos,String str){
		long start = System.currentTimeMillis();
		list.add(pos,str);
		return System.currentTimeMillis()-start;
	}
	
	public long benchMarkLinkedList(LinkedList<String> list,int pos,String str){
		long start = System.currentTimeMillis();
		list.add(pos,str);
		return System.currentTimeMillis()-start;
	}
	
	public long benchMarkAList(ArrayList<String> list,int position){
		long start = System.currentTimeMillis();
		list.remove(position);
		return System.currentTimeMillis()-start;
	}
	
	public long benchMarkLList(LinkedList<String> list,int position){
		long start = System.currentTimeMillis();
		list.remove(position);
		return System.currentTimeMillis()-start;
	}
}
